﻿#region Copyright and License
/*==============================================================================
 *  Copyright (c) cndotnet.org Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.cndotnet.org/ezsocio
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using System.Xml;
using System.Web;
using CNdotnet.Ezsocio.Core.Service;
using CNdotnet.Ezsocio.DataEntities;
using CNdotnet.Ezsocio.DataProvider;
using CNdotnet.Ezsocio.BusinessObjects;
using CNdotnet.Ezsocio.BusinessInterfaces;
using CNdotnet.Ezsocio.BusinessServices.Extensions;
using CNdotnet.Ezsocio.TemplateEngine;

namespace CNdotnet.Ezsocio.BusinessServices
{
    public class FriendGroupService : ServiceBase, IFriendGroupService
    {
        #region IFriendGroupService Members

        /// <summary>
        /// Gets the default groups.
        /// </summary>
        /// <returns></returns>
        public List<FriendGroupContract> GetDefaultGroups()
        {
            string groupsText = TemplateService.Generate(
                    new TemplateContract("DefaultFriendGroups"));
            List<FriendGroupContract> list = new List<FriendGroupContract>();
            foreach (var item in groupsText.Split(','))
            {
                list.Add(new FriendGroupContract { GroupName = item });
            }

            return list;
        }

        /// <summary>
        /// Gets the groups by user id.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <returns></returns>
        public List<FriendGroupContract> GetGroupsByUserId(int userID)
        {
            //List<FriendGroup> groups = LoadRepository<IFriendGroupRepository>().GetList("UserID=@0", null, userID);

            //var result = from g in groups
            //             select new FriendGroupContract
            //             {
            //                 GroupName = g.GroupName,
            //                 UserID = g.UserId,
            //                 ID = g.ID
            //             };
            //return result.ToList<FriendGroupContract>();
            return null;
        }

        /// <summary>
        /// Insert the group.
        /// </summary>
        /// <param name="group">The group.</param>
        public void InsertGroup(FriendGroupContract group)
        {
            FriendGroup friendGroup = group.ConvertToEntity();
            LoadRepository<IFriendGroupRepository>().Insert(friendGroup);
        }

        /// <summary>
        /// Update the group.
        /// </summary>
        /// <param name="group">The group.</param>
        public void UpdateGroup(FriendGroupContract group)
        {
            FriendGroup friendGroup = group.ConvertToEntity();
            LoadRepository<IFriendGroupRepository>().Update(friendGroup);
        }

        /// <summary>
        /// Delete the group.
        /// </summary>
        /// <param name="id">The id.</param>
        public void DeleteGroup(int id)
        {
            LoadRepository<IFriendGroupRepository>().Delete(id);
        }

        #endregion
    }
}
